package ConwaysGameOfLife;

/**
 *
 * @author Bryan
 */
//Color selection pallete for cells and background
public class ColorPallete extends javax.swing.JDialog {

    /**
     * Creates new form Color
     */
    final private WorldControlMediator mediator;
    private java.awt.Color currentColor;

    public ColorPallete(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.mediator = null;
        initComponents();
    }

    public ColorPallete(java.awt.Frame parent, boolean modal, WorldControlMediator mediator) {
        super(parent, modal);
        this.mediator = mediator;
        initComponents();
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        colorChooser = new javax.swing.JColorChooser();
        colorChooserCancel = new javax.swing.JButton();
        colorChooserOk = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setPreferredSize(new java.awt.Dimension(477, 358));

        colorChooserCancel.setText("Cancel");
        colorChooserCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                colorChooserCancelActionPerformed(evt);
            }
        });

        colorChooserOk.setText("Ok");
        colorChooserOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                colorChooserOkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(colorChooserOk, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(colorChooserCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(colorChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(colorChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(colorChooserCancel)
                    .addComponent(colorChooserOk))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 623, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void colorChooserCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_colorChooserCancelActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_colorChooserCancelActionPerformed

    private void colorChooserOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_colorChooserOkActionPerformed
        this.setVisible(false);
        currentColor = colorChooser.getColor();
        mediator.updateColors();

    }//GEN-LAST:event_colorChooserOkActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JColorChooser colorChooser;
    private javax.swing.JButton colorChooserCancel;
    private javax.swing.JButton colorChooserOk;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables

    public java.awt.Color getCurrentColor() {
        return currentColor;
    }

    public void setCurrentColor(java.awt.Color currentColor) {
        this.currentColor = currentColor;
        this.colorChooser.setColor(currentColor);
    }

}
